<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>基础配置信息</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${ctxLayui}/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctxLayui}/layuiadmin/style/admin.css" media="all">
	<link rel="stylesheet" href="${ctxLayui}/layuiadmin/style/myStyle.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb">
		<!--<a lay-href="">xx管理</a>-->
		<a><cite>基础配置信息</cite></a>
	</div>
</div>

<div class="layui-fluid">
	<div class="layui-card">

		<div class="layui-collapse" lay-filter="component-panel">
			<div class="layui-colla-item">
				<h2 class="layui-colla-title">搜索条件</h2>
				<div class="layui-colla-content">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">

							<div class="layui-inline layui-inline-31">
								<label class="layui-form-label">名称</label>
								<div class="layui-input-block">
									<input class="layui-input" name="name" autocomplete="off">
								</div>
							</div>

							<div class="layui-inline layui-inline-31">
								<label class="layui-form-label">值</label>
								<div class="layui-input-block">
									<input class="layui-input" name="val" autocomplete="off">
								</div>
							</div>

							<div class="layui-inline layui-inline-31">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-block">
									<select name="status"  id="status" >
									</select>
								</div>
							</div>

							<div class="layui-inline layui-inline-8">
								<button class="layui-btn" lay-submit lay-filter="baseConfig-list-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="layui-card-body">
			<table class="layui-hide" id="baseConfigListTable" lay-filter="baseConfigListTable"></table>
			<script type="text/html" id="baseConfigListTable-toolbar">
				<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="addRec">添加</button>
					<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delRec">删除</button>
				</div>
			</script>

			<script type="text/html" id="baseConfigListTable-bar">
				<a class="layui-btn layui-btn-xs" lay-event="editRec">编辑</a>
			</script>

		</div>
	</div>
</div>
<script src="${ctxLayui}/layuiadmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '${ctxLayui}/layuiadmin/'
	}).extend({
		index: 'lib/index'
	}).use(['index', 'table','dict','laydate','util'], function(){
		var $ = layui.$,table = layui.table,form = layui.form;
		var dict = layui.dict;
		var laydate = layui.laydate;
		var admin = layui.admin;
		var util = layui.util;
		dict.setSelect("status","status");
		var tplStatus = function(d){
			var html = dict.showName("status",d.status);
			return html;
		};


		var tableIns = table.render({
			elem:'#baseConfigListTable'
			,url: ctx+'/system/baseConfig/query'
			,cellMinWidth: 80
			,toolbar: '#baseConfigListTable-toolbar'
			,cols: [[
				{type: 'checkbox', fixed: 'left'}
				,{field:'name', title: '名称', align: 'center',width:200 }
				,{field:'val', title: '值', align: 'center',minWidth:200 }
				,{field:'sortOrder', title: '排序', align: 'center',width:80}
				,{field:'status', title: '状态', align: 'center',width:80,templet:tplStatus}
				,{title:'操作', toolbar: '#baseConfigListTable-bar', width:80}
			]]
			,page: true,
			limit: 10,
			limits: layui.setter.limits,
		});
		var active = {
			addRec: function(){
				window.formData = null;
				layer.open({
					type: 2
					,title: '用户信息'
					,content: 'baseConfigForm.jsp'
					,maxmin: true
					,area: layui.setter.area
					,btn: ['确定', '取消']
					,yes: function(index, layero){
						var iframeWindow = window['layui-layer-iframe'+ index]
							,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
						iframeWindow.layui.form.on('submit(layuiadmin-app-form-submit)', function(data){
							var field = data.field;
							var rtn = admin.syncReq(ctx+"/system/baseConfig/add",field);
							if(rtn && rtn.code==0){
								layer.msg('操作成功');
								active.reload();
								form.render();
								layer.close(index);
							}else{
								layer.msg('操作失败');
							}
						});
						submit.trigger('click');
					}
				});
			},
			editRec:function(obj){
				var rec = obj.data;
				window.formData = null;
				layer.open({
					type: 2
					,title: '用户信息'
					,content: 'baseConfigForm.jsp'
					,maxmin: true
					,area: layui.setter.area
					,btn: ['确定', '取消']
					,success:function(layero,index){
						var body = layer.getChildFrame('body', index);
						var data = obj.data;
						window.formData = data;
						$.each(data,function(item){
							body.find("[name="+item+"]").val(data[item]);
						});
					}
					,yes: function(index, layero){
						var iframeWindow = window['layui-layer-iframe'+ index]
							,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
						iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
							var field = data.field; 
							field.id = rec.id;
							var rtn = admin.syncReq(ctx+"/system/baseConfig/modify",field);
							if(rtn && rtn.code==0){
								layer.msg('操作成功');
								active.reload();
								form.render();
								layer.close(index);
							}else{
								layer.msg('操作失败');
							}
						});
						submit.trigger('click');
					}
				});
			},
			delRec:function () {
				var checkStatus = table.checkStatus('baseConfigListTable')
				var recs = checkStatus.data;
				if(!recs || recs.length<=0){
					layer.msg('请至少选择一条记录');
					return;
				}
				layer.confirm('确定删除'+recs.length+'条记录?', function(index){
					var idArr = [];
					for(var i=0;i<recs.length;i++){
						var rec = recs[i];
						idArr.push(rec.id);
					}
					var rtn = admin.syncReq(ctx+"/system/baseConfig/deleteByBatch",{"ids":idArr.join(",")});
					if(rtn && rtn.code==0){
						layer.msg('操作成功');
						active.reload();
					}else{
						layer.msg('操作失败');
					}
				});
			},
			reload: function(){
				tableIns.reload();
			},
		};
		table.on('toolbar(baseConfigListTable)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			switch(obj.event){
				case 'addRec':
					active.addRec()
					break;
				case 'delRec':
					active.delRec(checkStatus)
					break;
			};
		});
		table.on('tool(baseConfigListTable)', function(obj){
			var data = obj.data;
			if(obj.event === 'editRec'){
				active.editRec(obj);
			}
		});
		form.on('submit(baseConfig-list-search)', function(data){
			var field = data.field;
			table.reload('baseConfigListTable', {
				where: field
			});
		});
	});
</script>
</body>
</html>
